package cn.com.dbappsecurity.frame.datamodal;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PageDataModal implements IDataModal{

	private String path;
	private boolean forwared;
	private boolean success;
	/**
	 * 构造函数
	 * @param path	跳转到的路径
	 */
	public PageDataModal(boolean success,String path){
		this(success,path,true);
	}
	
	/**
	 * 构造函数
	 * @param path		跳转到的路径
	 * @param forwared	是否为服务器跳转
	 */
	public PageDataModal(boolean success,String path,boolean forwared){
		this.success = success;
		this.path = path;
		this.forwared = forwared;
	}

	@Override
	public void shipToResponse(HttpServletRequest req,
			HttpServletResponse resp) {
		try {
			if(forwared){
				req.getRequestDispatcher(path).forward(req,resp);
			}else{
				resp.sendRedirect(path);
			}
		} catch (Exception e) {
			LOG.error("页面跳转出错",e);
		}
	}

	@Override
	public boolean isSuccess() {
		return success;
	}

}
